<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户管理</title>

<link rel="stylesheet"
	href="assets/bootstrap-table/bootstrap-table.css">
<link rel="stylesheet"
	href="assets/bootstrap-table/bootstrap-editable.css">
<script src="assets/bootstrap-table/jquery.min.js"></script>
<script src="assets/bootstrap-table/bootstrap.min.js"></script>
<script src="assets/bootstrap-table/bootstrap-table.js"></script>
<script src="assets/bootstrap-table/bootstrap-table-export.js"></script>
<script src="assets/bootstrap-table/tableExport.js"></script>
<script src="assets/bootstrap-table/bootstrap-table-editable.js"></script>
<script src="assets/bootstrap-table/bootstrap-editable.js"></script>
<script src="js/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="./bootstrap/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>

<link rel="stylesheet" type="text/css" href="date/css/pikaday.css"/>
<script type="text/javascript" src="date/js/pikaday.min.js"></script>

<style>
.ml10 {
	margin-left: 10px;
}

#operate-success {

	font-size: 16px;
	background-color: #8AC007;
	color: #FBFBFB;
	visibility: hidden
}
</style>
</head>
<body>
	<div class="container">
		<div class="page-header">
			<h1>首页幻灯片栏&nbsp;&nbsp;</h1>
		</div>
		<div id="QRimg"></div>
		<div style="text-align: center;">
			<span id="operate-success">设置成功</span>
		</div>



		<div id="toolbar" class="btn-group">

			</div>
            
		    <div id="maintable">
			      <table id="table" data-id-field="foodId" 
					data-toolbar="#toolbar" data-height="80%"
					data-click-to-select="true">
					<thead>
						<tr>
						  <th data-align="left" data-field="id">Id</th>
							<th data-align="left" data-field="foodId">商品Id</th>
							<th data-align="left" data-field="name">名&nbsp;&nbsp;&nbsp;&nbsp;称</th>
							<th data-align="left" data-field="pic_url" data-formatter="actionImg">商品图片</th>							
							<th data-align="left" data-field="price" data-sortable="true">价格</th>
							<th data-align="left" data-field="homeImageManage" data-formatter="actionAdd">添加</th>
							<th data-align="left" data-field="homeImageManage" data-formatter="actionDelete">删除</th>
							<th data-align="left" data-field="homeImageManage" data-formatter="actionDetail">详情</th>
						</tr>
					</thead>
				</table>
		</div>
	</div>
	
<!-- 警告对话框 -->	
	<div class="modal fade" id="alertdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header blue">
                   <div >
                    	<strong id="alertchar" style="font-size:20px"></strong>
                   </div>
        
                   <div class="modal-footer">
			           <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			           <button type="button" id="commitFoodDataButton" class="btn btn-primary">确定</button>
	               </div> 
              </div>
         </div>
       </div>
   </div>
 
 <!-- 添加商品Modal start -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h3 class="modal-title" id="myModalLabel">添加幻灯片</h3>
				</div>
				<form id="dataCommit" class="form-horizontal" method="post"
					enctype="multipart/form-data" action="service/updateFoods.do">
					<div class="modal-body">
					
					  <div class="form-group">
							<label class="control-label col-md-4" for="categoryId2">修改幻灯片</label>
							<div class="input-group  col-md-5">
							   <select class="form-control" style="width:47%;padding:4px" id="categoryId2" name="parentId"
								class="selectpicker">
								</select>
							</div>							
						</div>
 			
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button"
							class="btn btn-primary" onclick="commitFoodDataButton();">提交更改</button>
					</div>
                      
                    <span id="thisId" style="display:none" value=""></span>
					<input type="file" name="myfile" style="display:none">
                    <input input class="form-control" type="text" id="foodId2" name="foodId" style="display:none">
				</form>
				<script type="text/javascript">
			
				    
				function commitFoodDataButton(){
				    //对表单的数据进行验证
				    var foodId=$("#categoryId2").val();
				    var id=$("#thisId").attr("value");
				    
				    $.post("insweptIndex/upPageSlides.do",{
                        id:id,
                        foodId:foodId
				    },function(text){
				    	if(text==-1||text==0){
				    		$("#myModal").modal('hide');
				    		setSuccess("失败。");
				    	}else{	
										setSuccess("更新成功。");
										
							    		$(" #table").bootstrapTable('refresh',{
							    			url : "insweptIndex/getPageSlides.do"
										});
									
				    		
				    		$("#myModal").modal('hide');
				    		
				    	}
				    });
				    
		    		
				    
				}
								
				</script>
			</div>
			<!-- /.modal-content -->
		</div>
	</div>
   
 <script type="text/javascript">
  function actionImg(value, row, index) {
		return ['<div class="detail-image">',
				'&nbsp;<img src="'+value+'" height="33px">&nbsp;',
				'</div>'].join('');
	}
 
   function getQueryString(name) {
	    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	    var r = window.location.search.substr(1).match(reg);
	    if (r != null) return unescape(r[2]); return null;
	    }
 
   var foodId=$('#content').attr('foodId');

        
	$("#table").bootstrapTable({
		url : "insweptIndex/getPageSlides.do"
	 });
	
  
	var obj = document.getElementById("categoryId2");
  
  function actionAdd(value, row, index) {
		return [
				'<a  href="javascript:void(0)" onclick="add(this);" title="添加">',
				'&nbsp;<img src="img/add.jpg" width="25px" height="25px">&nbsp;',
				'</a>'].join('');
}
  
  function add(temp){
		var hang = $(temp.parentNode).parent().prevAll().length+1;  //jquery获取td所在的行和列
		   //var lie = $(temp.parentNode).prevAll().length+1;  
		   //alert("第"+hang+"行"+"	"+"第"+lie+"列"); 

			 var val=document.getElementById("table").rows[hang].cells[1]; //取得所在列的值
		     var foodId=val.innerHTML; 
			 
			 var val0=document.getElementById("table").rows[hang].cells[0];
             var id=val0.innerHTML;
             
			 $("#thisId").attr("value",id);
			 
			 if(foodId!="-"){
				 alert("删除后再添加!");
				 return 0;
			 }
			 
		     $("#myModalLabel").text("添加商品");
				$("#myModal").modal('show');
				
				$.get(
						"insweptIndex/getAllFood.do",
						function(text) {
							obj.options.length = 0;//清楚modal的数据
							var json = eval('(' + text
								+ ')');
							for ( var i = 0; i < json.length; i++) {
								obj.options
								.add(new Option(
									json[i].name,
									json[i].foodId));
							}
						});
				
	}
  
  function actionDelete(value, row, index) {
		return [
				'<a  href="javascript:void(0)" onclick="Delete(this);" title="删除">',
				'&nbsp;<img src="img/delete.jpg" width="25px" height="25px">&nbsp;',
				'</a>'].join('');
}

  function Delete(temp){
		var hang = $(temp.parentNode).parent().prevAll().length+1;  //jquery获取td所在的行和列
		   //var lie = $(temp.parentNode).prevAll().length+1;  
		   //alert("第"+hang+"行"+"	"+"第"+lie+"列"); 

			 var val0=document.getElementById("table").rows[hang].cells[0];
             var id=val0.innerHTML;
             
             $.post("insweptIndex/deletePageSlides.do",{
                 id:id,
			    },function(text){
			    	if(text==-1||text==0){
			    		$("#myModal").modal('hide');
			    		setSuccess("失败。");
			    	}else{	
									setSuccess("删除成功。");
									
						    		$(" #table").bootstrapTable('refresh',{
						    			url : "insweptIndex/getPageSlides.do"
									});
								
			    		
			    		$("#myModal").modal('hide');
			    		
			    	}
			    });
		    
	}
 
  function actionDetail(value, row, index) {
		return [
				'<a  href="javascript:void(0)" onclick="detail(this);" title="点击查看商品详情">',
				'&nbsp;<img src="img/detail.jpg" width="25px" height="25px">&nbsp;',
				'</a>'].join('');
}
  
  function detail(temp){
		var hang = $(temp.parentNode).parent().prevAll().length+1;  //jquery获取td所在的行和列
		   //var lie = $(temp.parentNode).prevAll().length+1;  
		   //alert("第"+hang+"行"+"	"+"第"+lie+"列"); 

			 var val=document.getElementById("table").rows[hang].cells[1]; //取得所在列的值
		     var foodId=val.innerHTML; 

			 
		     $('#content').load('pages/fooddetail.html');
			   $('#content').attr('src','pages/fooddetail.html');
			   $('#content').attr('foodId',foodId);
	}
 </script>